<?php

class workflowComponents extends sfComponents
{

  public function executeInbox_widget (sfWebRequest $request)
  {
    $num_items = sfConfig::get('app_workflow_inbox_widget_num_items');
    
    $work_items = wfWorkflowWorkItemTable::getInstance()->retrieveUnreadForInbox($this->getUser()
      ->getGuardUser());
    $run_time_work_items = array();
    foreach ($work_items as $work_item)
    {
      $run_time_work_items[] = RunTimeWorkflowNodeFactory::getInstance()->create($work_item);
      if (count($run_time_work_items) == $num_items)
      {
        break;
      }
    }
    
    $this->work_items = $run_time_work_items;
    $this->num_spare_items = count($work_items) - $num_items;
  }

  public function executeNum_unread_work_items (sfWebRequest $request)
  {
    $this->num = count(wfWorkflowWorkItemTable::getInstance()->retrieveUnreadForInbox($this->getUser()
      ->getGuardUser()));
  }
}